package initalize

import (
	"fmt"
	_ "github.com/mbobakov/grpc-consul-resolver"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"sub_web/src/global"
	"sub_web/src/proto"
)

func InitConn() {
	fmt.Println(global.SrvConfig)
	conn, err := grpc.Dial(fmt.Sprintf("consul://%s:%d/%s?wait=14s",
		global.SrvConfig.ConsulConf.Host, global.SrvConfig.ConsulConf.Port, global.SrvConfig.SubServiceConf.Name),
		grpc.WithTransportCredentials(insecure.NewCredentials()),
		grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy":"round_robbin"}`))
	if err != nil {
		panic(err)
	}
	client := proto.NewSubscribeServiceClient(conn)
	global.SubClient = client
}
